package cn.edu.qzuie.artist.module.td.dal.mysql.worksimage;

import java.util.*;

import cn.edu.qzuie.artist.framework.common.pojo.PageResult;
import cn.edu.qzuie.artist.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.edu.qzuie.artist.framework.mybatis.core.mapper.BaseMapperX;
import cn.edu.qzuie.artist.module.td.controller.admin.work.vo.WorGetImageRespVO;
import cn.edu.qzuie.artist.module.td.dal.dataobject.worksimage.WorksImageDO;
import org.apache.ibatis.annotations.Mapper;
import cn.edu.qzuie.artist.module.td.controller.admin.worksimage.vo.*;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 作品集 Mapper
 *
 * @author 泉信管理员
 */
@Mapper
public interface WorksImageMapper extends BaseMapperX<WorksImageDO> {

    default PageResult<WorksImageDO> selectPage(WorksImagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WorksImageDO>()
                .likeIfPresent(WorksImageDO::getWorkName, reqVO.getWorkName())
                .ne(WorksImageDO::getSortOrder, 0)
                .orderByAsc(WorksImageDO::getId));

    }

    @Select("select * from td_works_image where work_id = #{workId}")
    List<WorksImageDO> getByWorkId(Long workId);

    @Select("delete from td_works_image where work_id = #{workId}")
    void deleteByWorkId(Long workId);
    // 删除作品用的
    @Update("update td_works_image set work_id= null where work_id=#{workId}")
    void updateByWorkId(Long workId);

    @Select("select * from td_works_image where work_id = #{workId} and sort_order = 0")
    WorksImageDO selectByWorkIdAndSort(Long workId);

    @Select("select img_src,describes from td_works_image where work_id=#{workId} and sort_order>=1 order by sort_order")
    List<WorGetImageRespVO> selectByImageWithDescribes(Long WorkId);
    @Update("update td_works_image set work_name = #{workName} where work_id = #{workId}" )
    void updateWorkName(WorksImageDO worksImage);
}